﻿using System.Web.UI;
using ElectronicCommerce.Framework.Web.Configuration;
using ElectronicCommerce.Framework.Web.Configuration.Resource;

namespace ElectronicCommerce.Framework.Web.Utility
{
    public class WebShareFunctions
    {
        public static Control GetUserControl(Control parentControl, string controlName)
        {
            if (string.IsNullOrEmpty(controlName)) return null;

            Control tempControl = null;
            foreach (Control curControl in parentControl.Controls)
            {
                if (curControl.ID == controlName)
                {
                    return curControl;
                }

                if (curControl.Controls.Count > 0)
                {
                    tempControl = GetUserControl(curControl, controlName);

                    if (tempControl != null) return tempControl;
                }
            }

            return null;
        }

        public static PageBelongType GetPageBelong(string pageName)
        {
            if (string.IsNullOrEmpty(pageName)) return PageBelongType.All;

            PageBelongType tempBelong = PageBelongType.All;
            PageInfo tempPage = ConfigHelper.PageConfig.GetPageInfo(pageName);
            if (tempPage != null)
            {
                if (tempPage.Belong.ToUpper() == PageBelongType.All.ToString().ToUpper()) tempBelong = PageBelongType.All;
                if (tempPage.Belong.ToUpper() == PageBelongType.Mall.ToString().ToUpper()) tempBelong = PageBelongType.Mall;
                if (tempPage.Belong.ToUpper() == PageBelongType.Merchant.ToString().ToUpper()) tempBelong = PageBelongType.Merchant;
            }

            return tempBelong;
        }
    }
}
